﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace SportsStore.Model
{
  public class CartItem
  {
    public CartItem()
    {
    }

    public CartItem(HttpContextBase context)
    {
      if (context.Session["CartId"] == null)
      {
        if (!string.IsNullOrWhiteSpace(context.User.Identity.Name))
        {
          context.Session["CartId"] = context.User.Identity.Name;
        }
        else
        {
          Guid tempCartId = Guid.NewGuid();
      
          context.Session["CartId"] = tempCartId.ToString();
        }
      }
      CartId = context.Session["CartId"].ToString();
    }

    public CartItem(int productId, string shoppingCartId, int quantity)
    {
      ProductId = productId;
      CartId = shoppingCartId;
      Quantity = quantity;
    }

    public int Id { get; set; }
    public string CartId { get; set; }
    public int ProductId { get; set; }
    public int Quantity { get; set; }
    public virtual Product Product { get; set; }
  }
}
